#!/bin/ash
# (C) Brad Conroy (technosaurus)
[ ! -d ${HOME}/.jwm ] && mkdir ${HOME}/.jwm
[ -f ${HOME}/.jwm/JWMRC ] || cp /etc/xdg/templates/JWMRC ${HOME}/.jwm/JWMRC
. ${HOME}/.jwm/JWMRC
[ -f ${HOME}/.jwmrc-tray ] || cp /etc/xdg/templates/jwmrc-tray ${HOME}/.jwmrc-tray

{	#localization block
[ $myLANG ] || myLANG=${LANGUAGE%% *}
[ $myLANG ] || myLANG=${LANG%_*}

[ -f /usr/share/locale/$myLANG/LC_MESSAGES/jwm ] && . /usr/share/locale/$myLANG/LC_MESSAGES/jwm
}

{	#parse .desktop files and sort generated menu entries into subcategories
for DESKTOP_FILE in /usr/share/applications/*.desktop ; do
	ICON="" CATS="" NAME="" EXEC="" LINE="" #prevent carryover from previous file
	while read LINE || [ "$LINE" ]; do
		case $LINE in
			Name=*|Name?${myLANG%_*}?=*) NAME="${LINE#*=}"'' ;; # sc0ttman... should use "Name[$myLANG]=" if found
#			Comment=*|Comment?${LANG%_*}?=*) COMMENT="${LINE#*=}"''  ;; #jwm doesn't support tooltips on menu items yet ... uncomment this if it ever does
			Icon=*) ICON="${LINE#*=}"''  ;;
			Categories=*) CATS="${LINE#*=}"'' ;;
			Exec=*) EXEC="${LINE#*=}"'' ;;
			NoDisplay=*true*) continue 2 ;; # skip this file
		esac
	done < $DESKTOP_FILE
	
	case $ICON in
		*.xpm|*.jpg|*.png|*.svg) ;; # extension provided, do nothing
		*) ICON=${ICON}.png	;; # no extension, add PNG
	esac

	[ "${EXEC}" ] && MenuEntry='<Program label="'${NAME}'" icon="'${ICON:-x16.xpm}'">'${EXEC}'</Program> 
		'
	#CATS="${CATS%;*}" # sc0ttman, keep just the first (or only) category.. everything before the semi-colon ;...no we may want multiple entries?
	for CAT in `echo ${CATS//;/	}` ; do
	#We are just going to build in the /etc/xdg/menus/hierarchy b/c its faster to inline it ... and Ctrl+Tab gets annoying
	case "$CAT" in
		X-Desktop|DesktopSettings|Screensaver|Accessibility)DesktopSettings=${DesktopSettings}${MenuEntry};;
		X-DesktopCountry)DesktopCountry=${DesktopCountry}${MenuEntry};;
		X-DesktopApplets)DesktopApplets=${DesktopApplets}${MenuEntry};;
		System|Monitor|Security|HardwareSettings|Core)SystemConfig=${SystemConfig}${MenuEntry};;
		X-SystemMemory)SystemMemory=${SystemMemory}${MenuEntry};;
		X-SystemSchedule)SystemSchedule=${SystemSchedule}${MenuEntry};;
		X-SetupEntry|PackageManager)SetupEntry=${SetupEntry}${MenuEntry};;
		X-SetupWizard)SetupWizard=${SetupWizard}${MenuEntry};;
		X-SetupUtility)SetupUtility=${SetupUtility}${MenuEntry};;
		Utility|Viewer|Development|Building|Debugger|IDE|Profiling|Translation|GUIDesigner)UtilityUtilities=${UtilityUtilities}${MenuEntry};; #sc0ttman utility typo
		Archiving)UtilityArchiving=${UtilityArchiving}${MenuEntry};;
		TerminalEmulator|Shell)UtilityConsole=${UtilityConsole}${MenuEntry};;
		FileSystem|FileManager)FilesystemManager=${FilesystemManager}${MenuEntry};;
		X-FilesystemMount)FilesystemMount=${FilesystemMount}${MenuEntry};;
		X-FilesystemUtility)FilesystemUtilities=${FilesystemUtilities}${MenuEntry};;
		X-FilesystemFind)FilesystemFind=${FilesystemFind}${MenuEntry};;
		2DGraphics|3DGraphics|Photography|Presentation|Chart|FlowChart)GraphicGraphics=${GraphicGraphics}${MenuEntry};;
		VectorGraphics|RasterGraphics)GraphicEdit=${GraphicEdit}${MenuEntry};;
		X-GraphicUtility)GraphicUtility=${GraphicUtility}${MenuEntry};;
		X-Document|WordProcessor|WebDevelopment)DocumentCompose=${DocumentCompose}${MenuEntry};;
		TextEditor)DocumentText=${DocumentText}${MenuEntry};;
		X-DocumentUtility|Dictionary)DocumentUtilities=${DocumentUtilities}${MenuEntry};;
		X-Calculate|Finance|Spreadsheet|ProjectManagement)BusinessSheets=${BusinessSheets}${MenuEntry};;
		Calculator)BusinessCalculator=${BusinessCalculator}${MenuEntry};;
		X-CalculateUtility)BusinessUtilities=${BusinessUtilities}${MenuEntry};;
		X-Personal|Calendar|ContactManagement)PersonalPlan=${PersonalPlan}${MenuEntry};;
		X-PersonalUtility)PersonalUtilities=${PersonalUtilities}${MenuEntry};;
		Dialup)NetworkDialup=${NetworkDialup}${MenuEntry};;
		Network|HamRadio|RemoteAccess)NetworkRemote=${NetworkRemote}${MenuEntry};;
		X-Internet|WebBrowser|Email|News|InstantMessaging|Telephony|IRCClient|FileTransfer|P2P)InternetWWW=${InternetWWW}${MenuEntry};;
		AudioVideo|Video|Player|AudioVideoEditing|Recorder|Music|Audio|Midi|Mixer|Sequencer|Tuner|Video|TV)MultimediaMedia=${MultimediaMedia}${MenuEntry};;
		DiskBurning)MultimediaBurn=${MultimediaBurn}${MenuEntry};;
		Game|Amusement|ActionGame|AdventureGame|ArcadeGame|BlocksGame|BoardGame|CardGame|KidsGame|LogicGame|RolePlaying|Simulation|SportsGame|StrategyGame)Fun=${Fun}${MenuEntry};;
		*);; #not messing with the rest of them for now this is what is in the template ...add Miscellaneous category?
	esac
	done
done
}

{	#generates submenus only if SUBMENU != ""
#SUBMENU is defined in the header - undefine it if you want flat(er) menus 
#add tweaks below to have your favorite sections in the main category menu instead of a subcategory
#
#the empty menu test evaluates as false if a submenu is empty ' [ "${DesktopSettings}" ] && ' <<prevents empty submenus
#if you want a certain group to be inlined into the main category submenu just comment out those lines here
#I gave up on trying to choose the subcategory icons from the given selection - feel free to take artistic license
if [ $SUBMENU ]; then
	[ "${DesktopSettings}" ] && DesktopSettings='<Menu label="'${jwm_DesktopSettings:-Settings}'" icon="x24.png" height="16">
		'${DesktopSettings}'
	</Menu>'
	[ "${DesktopCountry}" ] && DesktopCountry='<Menu label="'${jwm_DesktopCountry:-Country}'" icon="chooselocale.xpm" height="16">
		'${DesktopCountry}'
	</Menu>'
	[ "${DesktopApplets}" ] && DesktopApplets='<Menu label="'${jwm_DesktopApplets:-Applets}'" icon="mini-pager.xpm" height="16">
		'${DesktopApplets}'
	</Menu>'
	[ "${SystemConfig}" ] && SystemConfig='<Menu label="'${jwm_SystemConfig:-Info}'" icon="Card.xpm" height="16">
		'${SystemConfig}'
	</Menu>'
	[ "${SystemMemory}" ] && SystemMemory='<Menu label="'${jwm_SystemMemory:-Devices}'" icon="gparted.xpm" height="16">
		'${SystemMemory}'
	</Menu>'
	[ "${SystemSchedule}" ] && SystemSchedule='<Menu label="'${jwm_SystemSchedule:-Schedule}'" icon="mini-clock.xpm" height="16">
		'${SystemSchedule}'
	</Menu>'
	[ "${SetupEntry}" ] && SetupEntry='<Menu label="'${jwm_SetupEntry:-System}'" icon="package.xpm" height="16">
		'${SetupEntry}'
	</Menu>'
	[ "${SetupWizard}" ] && SetupWizard='<Menu label="'${jwm_SetupWizard:-Wizard}'" icon="wizard16.xpm" height="16">
		'${SetupWizard}'
	</Menu>'
	[ "${SetupUtility}" ] && SetupUtility='<Menu label="'${jwm_SetupUtility:-Utility}'" icon="mini-ray.xpm" height="16">
		'${SetupUtility}'
	</Menu>'
	[ "${UtilityUtilities}" ] && UtilityUtilities='<Menu label="'${jwm_UtilityUtilities:-Utilities}'" icon="mini-opensshd.xpm" height="16">
		'${UtilityUtilities}'
	</Menu>'
	[ "${UtilityArchiving}" ] && UtilityArchiving='<Menu label="'${jwm_UtilityArchiving:-Archiving}'" icon="mini-diskette.xpm" height="16">
		'${UtilityArchiving}'
	</Menu>'
	[ "${UtilityConsole}" ] && UtilityConsole='<Menu label="'${jwm_UtilityConsole:-Console}'" icon="mini-term.xpm" height="16">
		'${UtilityConsole}'
	</Menu>'
	[ "${FilesystemManager}" ] && FilesystemManager='<Menu label="'${jwm_FilesystemManager:-Manage}'" icon="dir_o.xpm" height="16">
		'${FilesystemManager}'
	</Menu>'
	[ "${FilesystemMount}" ] && FilesystemMount='<Menu label="'${jwm_FilesystemMount:-Mount}'" icon="mini-diskette.xpm" height="16">
		'${FilesystemMount}'
	</Menu>'
	[ "${FilesystemUtilities}" ] && FilesystemUtilities='<Menu label="'${jwm_FilesystemUtilities:-Utilities}'" icon="mini-opensshd.xpm" height="16">
		'${FilesystemUtilities}'
	</Menu>'
	[ "${FilesystemFind}" ] && FilesystemFind='<Menu label="'${jwm_FilesystemFind:-Find}'" icon="mini-zoom.xpm" height="16">
		'${FilesystemFind}'
	</Menu>'
	[ "${GraphicGraphics}" ] && GraphicGraphics='<Menu label="'${jwm_GraphicGraphics:-Graphics}'" icon="mini-paint.xpm" height="16">
		'${GraphicGraphics}'
	</Menu>'
	[ "${GraphicEdit}" ] && GraphicEdit='<Menu label="'${jwm_GraphicEdit:-Edit}'" icon="mini-palette.xpm" height="16">
		'${GraphicEdit}'
	</Menu>'
	[ "${GraphicUtility}" ] && GraphicUtility='<Menu label="'${jwm_GraphicUtility:-Utility}'" icon="mini-camera.xpm" height="16">
		'${GraphicUtility}'
	</Menu>'
	[ "${DocumentCompose}" ] && DocumentCompose='<Menu label="'${jwm_DocumentCompose:-Compose}'" icon="mini-edit.xpm" height="16">
		'${DocumentCompose}'
	</Menu>'
	[ "${DocumentText}" ] && DocumentText='<Menu label="'${jwm_DocumentText:-Text}'" icon="mini.text.xpm" height="16">
		'${DocumentText}'
	</Menu>'
	[ "${DocumentUtilities}" ] && DocumentUtilities='<Menu label="'${jwm_DocumentUtilities:-Utilities}'" icon="mini-book1.xpm" height="16">
		'${DocumentUtilities}'
	</Menu>'
	[ "${BusinessSheets}" ] && BusinessSheets='<Menu label="'${jwm_BusinessSheets:-Sheets}'" icon="spreadsheet.xpm" height="16">
		'${BusinessSheets}'
	</Menu>'
	[ "${BusinessCalculator}" ] && BusinessCalculator='<Menu label="'${jwm_BusinessCalculator:-Calculator}'" icon="mini-calc.xpm" height="16">
		'${BusinessCalculator}'
	</Menu>'
	[ "${BusinessUtilities}" ] && BusinessUtilities='<Menu label="'${jwm_BusinessUtilities:-Utilities}'" icon="mini-opensshd.xpm" height="16">
		'${BusinessUtilities}'
	</Menu>'
	[ "${PersonalPlan}" ] && PersonalPlan='<Menu label="'${jwm_PersonalPlan:-Plan}'" icon="mini-clipboard.xpm" height="16">
		'${PersonalPlan}'
	</Menu>'
	[ "${PersonalUtilities}" ] && PersonalUtilities='<Menu label="'${jwm_PersonalUtilities:-Utilities}'" icon="notecase16.xpm" height="16">
		'${PersonalUtilities}'
	</Menu>'
	[ "${NetworkDialup}" ] && NetworkDialup='<Menu label="'${jwm_NetworkDialup:-Dialup}'" icon="phone16.xpm" height="16">
		'${NetworkDialup}'
	</Menu>'
	[ "${NetworkRemote}" ] && NetworkRemote='<Menu label="'${jwm_NetworkRemote:-Remote}'" icon="mini-telnet.xpm" height="16">
		'${NetworkRemote}'
	</Menu>'
#only 1 subcategory, but probably needs more - like chat and WWW and ?... or maybe add WWW in Network?
#	[ "${InternetWWW}" ] && InternetWWW='<Menu label="'${jwm_InternetWWW:-WWW}'" icon="mini-www.xpm" height="16">
#		'${InternetWWW}'
#	</Menu>'
	[ "${MultimediaMedia}" ] && MultimediaMedia='<Menu label="'${jwm_MultimediaMedia:-Media}'" icon="Animation.xpm" height="16">
		'${MultimediaMedia}'
	</Menu>'
	[ "${MultimediaBurn}" ] && MultimediaBurn='<Menu label="'${jwm_MultimediaBurn:-Burn}'" icon="mini-cd.xpm" height="16">
		'${MultimediaBurn}'
	</Menu>'
#There is only 1 category right now, so this would be pointless
#	[ "${Fun}" ] && Fun='<Menu label="'${jwm_Fun:-Fun}'" icon="x16.xpm" height="16">
#		'${Fun}'
#	</Menu>'

fi
}

{	#Now generate the full menu with some formatting
MENU='<Menu label="'${jwm_Desktop:-Desktop}'" icon="x24.png" height="16">
	'${DesktopSettings}'
<Separator/>
	'${DesktopCountry}'
<Separator/>
	'${DesktopApplets}'
</Menu>
<Menu label="'${jwm_System:-System}'" icon="pc24.png" height="16">
	'${SystemConfig}'
<Separator/>
	'${SystemMemory}'
<Separator/>
	'${SystemSchedule}'
</Menu>
<Menu label="'${jwm_Setup:-Setup}'" icon="configuration24.png" height="16">
	'${SetupEntry}'
<Separator/>
	'${SetupWizard}'
<Separator/>
	'${SetupUtility}'
</Menu>
<Separator/>
<Menu label="'${jwm_Utility:-Utility}'" icon="utility24.png" height="16">
	'${UtilityUtilities}'
<Separator/>
	'${UtilityArchiving}'
<Separator/>
	'${UtilityConsole}'
</Menu>
<Menu label="'${jwm_Filesystem:-Filesystem}'" icon="folder24.png" height="16">
	'${FilesystemManager}'
<Separator/>
	'${FilesystemMount}'
<Separator/>
	'${FilesystemUtilities}'
<Separator/>
	'${FilesystemFind}'
</Menu>
<Menu label="'${jwm_Graphic:-Graphic}'" icon="paint24.png" height="16">
	'${GraphicGraphics}'
<Separator/>
	'${GraphicEdit}'
<Separator/>
	'${GraphicUtility}'
</Menu>
<Menu label="'${jwm_Document:-Document}'" icon="word24.png" height="16">
	'${DocumentCompose}'
<Separator/>
	'${DocumentText}'
<Separator/>
	'${DocumentUtilities}'
</Menu>
<Menu label="'${jwm_Business:-Business}'" icon="spread24.png" height="16">
	'${BusinessSheets}'
<Separator/>
	'${BusinessCalculator}'
<Separator/>
	'${BusinessUtilities}'
</Menu>
<Menu label="'${jwm_Personal:-Personal}'" icon="date24.png" height="16">
	'${PersonalPlan}'
<Separator/>
	'${PersonalUtilities}'
</Menu>
<Menu label="'${jwm_Network:-Network}'" icon="connect24.png" height="16">
	'${NetworkDialup}'
<Separator/>
	'${NetworkRemote}'
</Menu>
<Menu label="'${jwm_Internet:-Internet}'" icon="www24.png" height="16">
	'${InternetWWW}'
</Menu>
<Menu label="'${jwm_Multimedia:-Multimedia}'" icon="multimedia24.png" height="16">
	'${MultimediaMedia}'
<Separator/>
	'${MultimediaBurn}'
</Menu>
<Menu label="'${jwm_Fun:-Fun}'" icon="games24.png" height="16">
	'${Fun}'
</Menu>
'
}

{	#Add the header and footer to the Menu
MENU='<?xml version="1.0"?><JWM>
<!-- generated by '$0' -->
<RootMenu label="Menu" labeled="false" height="24" onroot="3">
'"$MENU"'
<Separator/>

<Program label="'${jwm_Help:-Help}'" icon="help24.png">exec defaulthtmlviewer file:///usr/share/doc/index.html</Program>

<Menu label="'${jwm_Shutdown:-Shutdown}'" icon="shutdown24.png" height="16">
	<Exit confirm="false" label="'${jwm_Exit:-Logout}'" icon="prompt16.xpm" />
	<!-- <Program label="'${jwm_Exit:-Logout}'" icon="prompt16.xpm">exec wmexit</Program> -->
	<Program label="'${jwm_Reboot:-Reboot computer}'" icon="mini-turn.xpm">exec wmreboot</Program>
	<Program label="'${jwm_Poweroff:-Power off computer}'" icon="mini-stop.xpm">exec wmpoweroff</Program>
	<Program label="'${jwm_RestartX:-Restart X server}'" icon="mini-x.xpm">restartwm</Program>
	<Program label="'${jwm_SwitchOpenbox:-Switch to Openbox WM}'" icon="mini-windows.xpm">restartwm openbox-session</Program>
	<Restart label="'${jwm_RestartJWM:-Restart jwm}'" icon="mini-windows.xpm"/>
</Menu>
</RootMenu>
'
}

{	#generates the drive icon tray if DRIVES != ""
if [ $DRIVES ]; then
	MENU=${MENU}'
<Tray layout="horizontal" halign="center" y="-30" layer="0" border="1">'
	for UEVENT in /sys/dev/block/*/uevent ; do
		. $UEVENT
		case ${DEVNAME:0:2} in
			sd)	REMOVABLE="0" NOTSWAP="1" LOGICAL=1
				[ -e ${UEVENT//uevent/"../removable"} ] && read REMOVABLE <${UEVENT//uevent/"../removable"} 
				[ $REMOVABLE = 1 ] && ICON=usbdrv48.png || ICON=drive48.png #possibly have something here for devicehandler?
				#logical partitions have a size of 2
				read LOGICAL <${UEVENT//uevent/size} 
				LINE=""
				while read LINE || [ "$LINE" ]; do
					case $LINE in 
						"/dev/"$DEVNAME*)NOTSWAP=""
					esac
				done < /proc/swaps
				
				[ ${DEVTYPE} = "partition" ] && [ $NOTSWAP ] && [ ! $LOGICAL = 2 ] && MENU=${MENU}'
	<TrayButton popup="'${DEVNAME}'" icon="'${ICON}'">exec:devicehandler '${DEVNAME}'</TrayButton>';;
			mm) [ ${DEVTYPE} = "partition" ] && MENU=${MENU}'
	<TrayButton popup="'${DEVNAME}'" icon="card48.png">exec:devicehandler '${DEVNAME}'</TrayButton>';;
			sr)MENU=${MENU}'
	<TrayButton popup="'${DEVNAME}'" icon="optical48.png">exec:devicehandler '${DEVNAME}'</TrayButton>';;
			fd)MENU=${MENU}'
	<TrayButton popup="'${DEVNAME}'" icon="floppy48.png">exec:devicehandler '${DEVNAME}'</TrayButton>';;
		esac
	done
	MENU=${MENU}'
</Tray>
'
fi
}

{	#set icon paths
for DIR in ${ICONPATH}; do
	MENU=${MENU}'
<IconPath>'${DIR}'</IconPath>
'
done
}

#TODO DESKTOP:number,backgrounds etc... <Desktops width="3" height="1"/> ...done
#new todo for final - dont put empty tags ex. <Corner></Corner> when value is ""

{	#window styles
MENU=${MENU}'
<WindowStyle>
	<Font>'${WINDOWFONT}'</Font>
	<Width>'${WINDOWWIDTH}'</Width>
	<Height>'${WINDOWHEIGHT}'</Height>	 
	<Active>
		<Text>'${WINDOWACTTEXT}'</Text>
		<Title>'${WINDOWACTTITLE}'</Title>
		<Corner>'${WINDOWACTCORNER}'</Corner>
		<Outline>'${WINDOWACTOUTLINE}'</Outline>
	</Active>
	<Inactive>
		<Text>'${WINDOWINACTTEXT}'</Text>
		<Title>'${WINDOWINACTTITLE}'</Title>
		<Corner>'${WINDOWINACTCORNER}'</Corner>
		<Outline>'${WINDOWINACTOUTLINE}'</Outline>
	</Inactive>
</WindowStyle> 
'
}

{	#task list styles
MENU=${MENU}'
<TaskListStyle>
	<Font>'${TASKLISTFONT}'</Font>
	<ActiveForeground>'${TASKLISTACTFG}'</ActiveForeground>
	<ActiveBackground>'${TASKLISTACTBG}'</ActiveBackground>
	<Background>'${TASKLISTBG}'</Background>
</TaskListStyle>
'
}

{	#tray styles
MENU=${MENU}'
<TrayStyle>
	<Font>'${TRAYFONT}'</Font>
	<Foreground>'${TRAYFG}'</Foreground>
	<Background>'${TRAYBG}'</Background>
</TrayStyle>
'
}

{	#pager styles
MENU=${MENU}'
<PagerStyle>
	<Outline>'${PAGEROUTLINE}'</Outline>
	<Foreground>'${PAGERG}'</Foreground>
	<Background>'${PAGERBG}'</Background>
	<ActiveForeground>'${PAGERACTFG}'</ActiveForeground>
	<ActiveBackground>'${PAGERACTBG}'</ActiveBackground>
</PagerStyle>
'
}

{	#popup styles
MENU=${MENU}'
<PopupStyle>
	<Font>'${POPUPFONT}'</Font>
	<Outline>'${POPUPOUTLINE}'</Outline>
	<Foreground>'${POPUPFG}'</Foreground>
	<Background>'${POPUPBG}'</Background>
</PopupStyle>
'
}

{	#menu styles
MENU=${MENU}'
<MenuStyle>
	<Font>'${MENUFONT}'</Font>
	<Foreground>'${MENUFG}'</Foreground>
	<Background>'${MENUBG}'</Background>
	<ActiveForeground>'${MENUACTFG}'</ActiveForeground>
	<ActiveBackground>'${MENUACTBG}'</ActiveBackground>
</MenuStyle>
'
}

{	#desktop settings
MENU=${MENU}'
<Desktops count="'${DESKTOPS:-$((${DESKTOPWIDTH}*${DESKTOPHEIGHT}))}'" width="'${DESKTOPWIDTH}'" height="'${DESKTOPHEIGHT}'">
'
i=1 DESKNUM=1
while ([ $i -le ${DESKTOPHEIGHT} ]) do
	j=1
	while ([ $j -le ${DESKTOPWIDTH} ]) do
		DESKTOPNAME=$i","$j
		DESKTOPBGTYPE=`eval echo '$DESKTOPBG'${DESKNUM}'TYPE'`
		DESKTOPBG=`eval echo '$DESKTOPBG'${DESKNUM}`
		[ $DESKTOPBGTYPE ] && MENU=${MENU}'
	<Desktop name="'${DESKTOPNAME}'">
		<Background type="'${DESKTOPBGTYPE}'">'${DESKTOPBG}'</Background>
	</Desktop>
'
	DESKNUM=$(($DESKNUM+1))
	j=$(($j+1))
	done
	i=$(($i+1))
done

MENU=${MENU}'
</Desktops>
'
}

{	#group settings
i=0
while ([ $i -le "9" ]) do
	CLASS="" NAME=""
	GROUP=`eval echo '$GROUP'${i}`
	if [ "$GROUP" ];then
		MENU=${MENU}'
<Group>'
		for ENTRY in $GROUP; do
			case $ENTRY in
				CLASS=*)MENU=${MENU}'
	<Class>'${ENTRY#*=}'</Class>';;
				NAME=*)MENU=${MENU}'
	<Name>'${ENTRY#*=}'</Name>';;
				*)MENU=${MENU}'
	<Option>'${ENTRY}'</Option>';;
			esac
		done && MENU=${MENU}'
</Group>
'
	else
		break
	fi
i=$(($i+1))
done
}

{	#misc settings
MENU=${MENU}'
<!-- misc. parameters -->
<DoubleClickSpeed>'${DOUBLECLICKSPEED}'</DoubleClickSpeed>
<DoubleClickDelta>'${DOUBLECLICKDELTA}'</DoubleClickDelta>
<FocusModel>'${FOCUSMODEL}'</FocusModel>
<SnapMode distance="'${SNAPDISTANCE}'">'${SNAPMODE}'</SnapMode>
<MoveMode>'${MOVEMODE}'</MoveMode>
<ResizeMode>'${RESIZEMODE}'</ResizeMode>
'
}

{	#keybindings
for KEYS in $KEYBINDINGS ; do
case $KEYS in
	,*)KEYS=${KEYS#,};KEYBINDING='<Key key="'${KEYS%,*}'">'${KEYS#*,}'</Key>';;
	*)KEY=${KEYS%,*}
	KEYBINDING='<Key mask="'${KEYS%,*,*}'" key="'${KEY#*,}'">'${KEYS#*,*,}'</Key>';;
esac
MENU=${MENU}'
'$KEYBINDING
done
}

{	#additional include files (will override previous settings)
for INCLUDE in ${INCLUDES}; do
MENU=${MENU}'
<Include>'${INCLUDE}'</Include>'
done
}

echo "$MENU"'
</JWM>
' | while read A; do
case $A in
*Program*) [ "$A" != "$LAST" ] && echo "$A" && LAST=$A;;
*)echo "$A";;
esac
done > ${HOME}/.jwmrc
#todo trays, keys, groups, gui interface
#use /proc/self/mountstats /proc/swaps or /proc/partitions for drive info?
